package com.giser.testapp.lib.Tool;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import com.giser.testapp.MainActivity;
import com.giser.testapp.lib.App.GlobClass;

/**
 * Created by Lss on 2017/12/6.
 */

public class SystemSettingUtil {

    public static void setGPSOpen(Context mContext) {
        Intent intent = new Intent();
        intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            //((MainActivity)mContext).startActivity(intent);
            ((MainActivity)mContext).startActivityForResult(intent, GlobClass.SetGPS_CODE);
        } catch (ActivityNotFoundException ex) {
            // The Android SDK doc says that the location
            // settings activity
            // may not be found. In that case show the
            // general settings.
            // General settings activity
            intent.setAction(Settings.ACTION_SETTINGS);
            try {
               // ((MainActivity)mContext).startActivity(intent);
                ((MainActivity)mContext).startActivityForResult(intent, GlobClass.SetGPS_CODE);
            } catch (Exception e) {
            }
        }
    }

    public static void setNotify(Context mContext){
        EnvLog.i("1111");
        ((MainActivity)mContext).startActivityForResult(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"), GlobClass.SetNotify_CODE);
    }
    // 判断是否打开了通知监听权限
    /*public static boolean isEnabledNotify(Context context) {
        String pkgName = context.getPackageName();
        EnvLog.i("pkgName="+pkgName);
        final String flat = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
        EnvLog.i("flat="+flat);
        if (!TextUtils.isEmpty(flat)) {
            final String[] names = flat.split(":");
            for (int i = 0; i < names.length; i++) {
                final ComponentName cn = ComponentName.unflattenFromString(names[i]);
                EnvLog.i("cn="+cn.toString());
                if (cn != null) {
                    EnvLog.i("package="+cn.getPackageName());
                    if (TextUtils.equals(pkgName, cn.getPackageName())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }*/

}
